﻿<UserControl x:Class="Berico.SnagL.Infrastructure.Controls.SearchCriterion"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:customControls="clr-namespace:Berico.Windows.Controls;assembly=Berico.Windows.Controls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
    xmlns:common="clr-namespace:Berico.Common.UI.Templates;assembly=Berico.Common"     
    xmlns:convertors="clr-namespace:Berico.Common.UI.Converters;assembly=Berico.Common"    
    xmlns:ui="clr-namespace:Berico.SnagL.UI"
	xmlns:System="clr-namespace:System;assembly=mscorlib"             
    xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    ui:VisualStates.CurrentState="{Binding CurrentState}"             
    Height="35">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="LostFocus">
            <cmd:EventToCommand Command="{Binding LostFocusCommand}" PassEventArgsToCommand="False"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="GotFocus">
            <cmd:EventToCommand Command="{Binding GotFocusCommand}" PassEventArgsToCommand="False"/>
        </i:EventTrigger>        
    </i:Interaction.Triggers>

    <UserControl.Resources>
        <convertors:VisibilityConverter x:Key="VisibilityConverter" />
        
        <SolidColorBrush x:Key="Positive" Color="#FF2F8C2F" />
        <SolidColorBrush x:Key="Negative" Color="#FF8C2F2F" />

        <ControlTemplate x:Key="ValidationToolTipTemplate">
            <Grid x:Name="Root" Margin="5,0" Opacity="0" RenderTransformOrigin="0,0">
                <Grid.RenderTransform>
                    <TranslateTransform x:Name="xform" X="-25"/>
                </Grid.RenderTransform>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="OpenStates">
                        <VisualStateGroup.Transitions>
                            <VisualTransition GeneratedDuration="0"/>
                            <VisualTransition GeneratedDuration="0:0:0.2" To="Open">
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="xform">
                                        <DoubleAnimation.EasingFunction>
                                            <BackEase Amplitude=".3" EasingMode="EaseOut"/>
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Duration="0:0:0.2" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                                </Storyboard>
                            </VisualTransition>
                        </VisualStateGroup.Transitions>
                        <VisualState x:Name="Closed">
                            <Storyboard>
                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Open">
                            <Storyboard>
                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="xform"/>
                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border Background="#052A2E31" CornerRadius="5" Margin="4,4,-4,-4"/>
                <Border Background="#152A2E31" CornerRadius="4" Margin="3,3,-3,-3"/>
                <Border Background="#252A2E31" CornerRadius="3" Margin="2,2,-2,-2"/>
                <Border Background="#352A2E31" CornerRadius="2" Margin="1,1,-1,-1"/>
                <Border Background="#FFDC000C" CornerRadius="2"/>
                <Border CornerRadius="2">
                    <TextBlock Foreground="White" MaxWidth="250" Margin="8,4,8,4" TextWrapping="Wrap" Text="{Binding ErrorMessage}" UseLayoutRounding="false"/>
                </Border>
            </Grid>
        </ControlTemplate>

        <Style x:Key="AddButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="Background_Over" Storyboard.TargetProperty="Opacity" To="1"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="Background_Pressed" Storyboard.TargetProperty="Opacity" To="1"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DisabledVisual" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="Background" Stroke="{StaticResource Positive}" StrokeThickness="1" Fill="Gray" />
                            <Ellipse x:Name="Background_Over" Stroke="#FF749FD2" StrokeThickness="1" Opacity="0" Fill="#FFB1C7E0" />
                            <Ellipse x:Name="Background_Pressed" Margin="1" Opacity="0" Fill="#FF787878" />
                            <Ellipse x:Name="BackgroundGradient" Margin="1">
                                <Ellipse.Fill>
                                    <RadialGradientBrush GradientOrigin="0.5,1">
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="-1" ScaleY="-1"/>
                                                <SkewTransform CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0" Y="-0.15"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FCFFFFFF"/>
                                        <GradientStop Color="#4CFFFFFF" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Path x:Name="PlusSign" Margin="4" Stretch="Fill" Fill="#FFFFFFFF" Stroke="{StaticResource Positive}" Data="F1 M 34.125,2L 66.125,2L 66.125,34L 98,34L 98,66L 66.125,66L 66.125,97.875L 34.125,97.875L 34.125,66L 1.99997,66L 1.99997,34L 34.125,34L 34.125,2 Z " Visibility="Visible"/>
                            <!--<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>-->
                            <Ellipse x:Name="DisabledVisual" Visibility="Collapsed" Opacity=".55" Stroke="#FFA3AEB9" Fill="White"/>
                            <Ellipse x:Name="FocusVisual" Stroke="#FF6DBDD1" StrokeThickness="1" Margin="1" IsHitTestVisible="false" Opacity="0"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style x:Key="RemoveButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="Background_Over" Storyboard.TargetProperty="Opacity" To="1"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="Background_Pressed" Storyboard.TargetProperty="Opacity" To="1"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DisabledVisual" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="Background" Stroke="{StaticResource Negative}" StrokeThickness="1" Fill="Gray" />
                            <Ellipse x:Name="Background_Over" Stroke="#FF749FD2" StrokeThickness="1" Opacity="0" Fill="#FFB1C7E0" />
                            <Ellipse x:Name="Background_Pressed" Margin="1" Opacity="0" Fill="#FF787878" />
                            <Ellipse x:Name="BackgroundGradient" Margin="1">
                                <Ellipse.Fill>
                                    <RadialGradientBrush GradientOrigin="0.5,1">
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="-1" ScaleY="-1"/>
                                                <SkewTransform CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0" Y="-0.15"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FCFFFFFF"/>
                                        <GradientStop Color="#4CFFFFFF" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Rectangle x:Name="MinusSign" Height="8" Margin="5,0,5,0" Stretch="Fill" Fill="#FFFFFFFF" Stroke="{StaticResource Negative}" Visibility="Visible"/>
                            <!--<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>-->
                            <Ellipse x:Name="DisabledVisual" Visibility="Collapsed" Opacity=".55" Stroke="#FFA3AEB9" Fill="White"/>
                            <Ellipse x:Name="FocusVisual" Stroke="#FF6DBDD1" StrokeThickness="1" Margin="1" IsHitTestVisible="false" Opacity="0"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="00:00:00" To="Disabled"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Normal"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="ActivityStates">
                <VisualState x:Name="Inactive">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AddButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="RemoveButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="InactiveVisual" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AttributeCombo" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="False" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="OperationCombo" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="False" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="SearchEditor" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Active">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AddButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="RemoveButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="InactiveVisual" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AttributeCombo" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="True" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="OperationCombo" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="True" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="SearchEditor" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Unfocused"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Border BorderBrush="#FFA5A5A5" BorderThickness="1">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFFFFFF"/>
                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                    <GradientStop Color="#FFE0E0E0" Offset="0.49"/>
                    <GradientStop Color="#FFE0E0E1" Offset="0.50"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid Margin="0,2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="35" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                
                <!-- Button to add this criterion -->
                <Button x:Name="AddButton" Grid.Column="0" Height="25" Width="25" Style="{StaticResource AddButtonStyle}" Visibility="Collapsed">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cmd:EventToCommand Command="{Binding AddButtonClickedCommand}" PassEventArgsToCommand="False"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>

                <!-- Button to remove this criterion -->
                <Button x:Name="RemoveButton" Grid.Column="0" Height="25" Width="25" Style="{StaticResource RemoveButtonStyle}" Visibility="Collapsed">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cmd:EventToCommand Command="{Binding RemoveButtonClickedCommand}" PassEventArgsToCommand="False"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>

                <Grid Grid.Column="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" MinWidth="120" /><!-- Attribute List -->
                        <ColumnDefinition Width="Auto" MinWidth="120" /><!-- Operation List -->
                        <ColumnDefinition Width="Auto" MinWidth="125" /><!-- Criterion Value -->
                    </Grid.ColumnDefinitions>
                    <ComboBox x:Name="AttributeCombo" Grid.Column="0" Height="25" Margin="2,0,2,0" ItemsSource="{Binding Parent.Attributes}" SelectedValue="{Binding SelectedAttribute, Mode=TwoWay}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <cmd:EventToCommand Command="{Binding SelectedAttributeChangedCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ComboBox>
                    <ComboBox x:Name="OperationCombo" Grid.Column="1" Height="25" Margin="2,0,2,0" ItemsSource="{Binding Parent.Operators}" SelectedValue="{Binding SelectedOperator, Mode=TwoWay}" />
                    <!--<TextBox x:Name="ValueTextBox" Grid.Column="3" Height="25"  Margin="1,0,1,0" FontSize="10" Text="{Binding Value, Mode=TwoWay}" VerticalContentAlignment="Bottom" />-->
                    <common:EditorTemplateSelector x:Name="SearchEditor" Grid.Column="2" Height="25" Margin="2,0,4,0" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" TargetSelectorKey="{Binding SelectorKey, Mode=TwoWay}" DefaultSelectorKey="PLAIN_TEXT">
                        <common:EditorTemplateSelector.DataTemplates>
                            <common:KeyedDataTemplate SelectorKey="PLAIN_TEXT">
                                <TextBox FontSize="10" Text="{Binding Value, Mode=TwoWay}" VerticalContentAlignment="Bottom" Width="Auto" HorizontalAlignment="Stretch" />
                            </common:KeyedDataTemplate>
                            <common:KeyedDataTemplate SelectorKey="BOOLEAN">
                                <CheckBox IsChecked="{Binding Value, Mode=TwoWay}" />
                            </common:KeyedDataTemplate>
                            <common:KeyedDataTemplate SelectorKey="DATE">
                                <sdk:DatePicker Text="{Binding Value, Mode=TwoWay}" />
                            </common:KeyedDataTemplate>
                        </common:EditorTemplateSelector.DataTemplates>
                    </common:EditorTemplateSelector>

                    <!-- Textual description of a criteria -->
                    <!--<Border x:Name="CriteriaDescriptionView" Grid.Column="1" Grid.ColumnSpan="4" Background="AntiqueWhite" Visibility="Collapsed">
                        <TextBlock x:Name="CriteriaDescription" Grid.Column="1" Grid.ColumnSpan="6" HorizontalAlignment="Left" VerticalAlignment="Center" />
                    </Border>-->
                </Grid>
                <Rectangle x:Name="InactiveVisual" Grid.Column="1" Fill="White" Opacity=".60" IsHitTestVisible="False" Visibility="Collapsed" />
            </Grid>
        </Border>

        <Border x:Name="FocusVisual" Grid.Column="1" Margin="-2" BorderThickness="2" IsHitTestVisible="False" Visibility="Collapsed" BorderBrush="#B24A75A9"/>

        <!-- The validation element, borrowed from the standard control template -->
        <Border x:Name="ValidationVisual" Margin="1" BorderBrush="#FFDB000C" BorderThickness="2" CornerRadius="1" Visibility="{Binding IsValid, Converter={StaticResource VisibilityConverter}, ConverterParameter='true', FallbackValue=Collapsed}">
            <ToolTipService.ToolTip>
                <ToolTip x:Name="validationTooltip" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Template="{StaticResource ValidationToolTipTemplate}">
                    <ToolTip.Triggers>
                        <EventTrigger RoutedEvent="Canvas.Loaded">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="validationTooltip">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <System:Boolean>true</System:Boolean>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToolTip.Triggers>
                </ToolTip>
            </ToolTipService.ToolTip>
            <Grid Background="Transparent" HorizontalAlignment="Right" Height="10" Margin="0,-4,-4,0" VerticalAlignment="Top" Width="10">
                <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C" Margin="-1,3,0,0"/>
                <Path Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff" Margin="-1,3,0,0"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>
